<%@ page pageEncoding="UTF-8"%>
<%@ include file="../commons/head.jsp"%>
<style>
td {
	padding-top: 5px;
	padding-bottom: 5px;
	padding-right: 5px;
}

td:first-child {
	padding-left: 5px;
	padding-right: 0;
}

.error {
	color: red;
	font-style: normal;
	font-weight: bold;
}

.success {
	color: green;
	font-style: normal;
	font-weight: bold;
}
</style>
<script type="text/javascript">
$(function(){
	$("#cellPhone").focus(function(){
		$("#err").text("");
	});
	
	$("#cellPhone").blur(function(){
		var rex=/^1[3-8]+\d{9}$/;
		var cellPhone = $("#cellPhone").val();
		if(cellPhone ==null ||cellPhone.length==0){
			$("#err").text("");
			return;
		}
		if(cellPhone.length != 11 || !rex.test(cellPhone)){
			$("#err").text("请输入正确的手机号！");
			return;
		}
		$.ajax({
			url:"${pageContext.request.contextPath}/balance/getMember",
			cache:false,
			ansyc:true,
			type:"post",
			data:{"cellphone":cellPhone},
			success:function(data){
				if(data.cellPhone==null){
					$("#err").text("账号不存在！");
					return
				}else{
					$("#err").text("");
					$("#memberName").val(data.memberName);
					$("#bankCardId").val(data.bankCardId);
					$("#bankName").val(data.bankName);
					$("#avaibleCash").val(data.avaibleCash);
				}
				console.log(data);
			}
		});
	});
	
	$("#subm").click(function(){debugger
		var cellPhone = $("#cellPhone").val()
		var memberName = $("#memberName").val();
		var bankCardId = $("#bankCardId").val();
		var bankName = $("#bankName").val();
		var avaibleCash = $("#avaibleCash").val();
		var withdrawCash = $("#withdrawCash").val();
		var flag = true;
		if(cellPhone==null || cellPhone==''){
			$.messager.alert("提现","请先输入会员手机号");
			return false;
		}
		if(bankCardId==null || bankCardId==""){
			$.messager.alert("提现","请先绑定银行卡");
			flag=false;
		}
		if(!/^([1-9]\d{0,9}|0)([.]?|(\.\d{1,2})?)$/.test(withdrawCash)||withdrawCash==0){
			$.messager.alert("提现","请输入正确的金额数值");
			return false;
		}
		if(withdrawCash-avaibleCash>0){
			$.messager.alert("提现","余额不足");
			flag=false;
		}
		if(!flag){
			return false;
		}else{
			$.messager.confirm("确认","确认要提现"+withdrawCash+"元？",function(r){
				if(r){
					$.ajax({
						url:"${pageContext.request.contextPath}/balance/saveOne",
						cache:false,
						ansyc:true,
						data:{"cellPhone":cellPhone,"memberName":memberName,"bankCardId":bankCardId,
							"bankName":bankName,"avaibleCash":avaibleCash,"withdrawCash":withdrawCash},
						success:function(data){
							if(data.result==1){
								$.messager.alert("提现","提现成功");
								$("#cellPhone").val("")
								$("#memberName").val("");
								$("#bankCardId").val("");
								$("#bankName").val("");
								$("#avaibleCash").val("");
								$("#withdrawCash").val("");
							}else{
								$.messager.alert("提现","提现失败");
							}
							console.log(data);
						}
					});
				}
			});
		}
		
	});
	
})
</script>
<body>
<div class="jianju">
<h3>余额提现</h3>
	<div class="container-fluid">
		<form class="form-horizontal" method="post" id="form1">
			<div class="form-group">
				<label for="cellPhone" class="col-md-3 control-label">会员手机号：</label>
				<div class="col-md-2">
				<input class="form-control" name="cellPhone" id="cellPhone">
				</div>
				<div class="col-md-3">
					<label class="error" id="err"></label>
				</div>
			</div>
				
			<div class="form-group">
				<label for="memberName" class="col-md-3 control-label">会员姓名：</label>
				 <div class="col-md-2">
					<input class="form-control" readonly="true" name="memberName" id="memberName">
				</div> 
			</div>
			
			<div class="form-group">
				<label for="bankCardId" class="col-md-3 control-label">银行卡号：</label>
				<div class="col-md-2">
				<input class="form-control" readonly="true" name="bankCardId" id="bankCardId">
				</div>
				<div class="col-md-3">
					<label class="error" id="bankCardIdErr"></label>
				</div>
			</div>
				
			<div class="form-group">
				<label for="bankName" class="col-md-3 control-label">银行名称：</label>
				 <div class="col-md-2">
					<input class="form-control" readonly="true" name="bankName" id="bankName">
				</div> 
				<div class="col-md-3">
					<label class="error" id="bankNameErr"></label>
				</div>
			</div>
			
				
			<div class="form-group">
				<label for="avaibleCash" class="col-md-3 control-label">可提现（元）：</label>
				 <div class="col-md-2">
					<input class="form-control" readonly="true" name="avaibleCash" id="avaibleCash">
				</div> 
			</div>
			
			<div class="form-group">
				<label for="withdrawCash" class="col-md-3 control-label">本次提现（元）：</label>
				 <div class="col-md-2">
					<input class="form-control" name="withdrawCash" id="withdrawCash">
				</div> 
				<div class="col-md-3">
					<label class="error" id="withdrawCashErr"></label>
				</div>
			</div>
			<hr style="width: 98%;">
			<div class="form-group">
				<div class="col-md-3"></div>
				<div class="col-md-2"><button class="easyui-linkbutton l-btn l-btn-small" style="width:100px;height:30px" iconcls="icon-ok" id="subm" type="button" heightclass="btn btn-primary btn-lg" group="">提现<span class="l-btn-icon icon-ok">&nbsp;</span></button></div>
			</div>
		</form>
	</div>
	</div>
</body>